package com.fengpb.friday.conductor.client.controller;

import com.fengpb.friday.conductor.core.execution.WorkflowExecutor;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("workflow")
public class WorkflowController {

    private final WorkflowExecutor workflowExecutor;

    public WorkflowController(WorkflowExecutor workflowExecutor) {
        this.workflowExecutor = workflowExecutor;
    }

    @PostMapping("start/{workflowName}/{version}")
    public Map<String, Object> start(@PathVariable(name = "workflowName") String workflowName
            , @PathVariable(name = "version") int version, @RequestBody Map<String, Object> input) {
        return workflowExecutor.startWorkflowWithOutput(workflowName, version, input);
    }
}
